package com.ruoyi.web.controller.ydz;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.ClinicalNews;
import com.ruoyi.web.service.IClinicalNewsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 临床招募新闻Controller
 * 
 * @author drx
 * @date 2024-04-22
 */
@Controller
@RequestMapping({"/ydz/clinicalnews","/api/clinicalnews"})
@Api(tags = "临床招募新闻")
public class ClinicalNewsController extends BaseController
{
    private String prefix = "ydz/clinicalnews";

    @Resource
    private IClinicalNewsService clinicalNewsService;

    @RequiresPermissions("ydz:clinicalnews:view")
    @GetMapping()
    public String news()
    {
        return prefix + "/clinicalnews";
    }

    /**
     * 查询临床招募新闻列表
     */
    @RequiresPermissions("ydz:clinicalnews:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询临床招募新闻列表")
    public TableDataInfo list(ClinicalNews clinicalNews)
    {
        startPage();
        List<ClinicalNews> list = clinicalNewsService.selectClinicalNewsList(clinicalNews);
        return getDataTable(list);
    }

    /**
     * 查询临床招募新闻列表
     */
    @PostMapping("/selectClinicalNewsList")
    @ResponseBody
    @ApiOperation("查询临床招募新闻列表")
    public TableDataInfo selectClinicalNewsList(@RequestBody ClinicalNews clinicalNews)
    {
        startPage();
        List<ClinicalNews> list = clinicalNewsService.selectClinicalNewsList(clinicalNews);
        return getDataTable(list);
    }

    /**
     * 修改保存临床招募新闻列表
     */
    @ApiOperation("修改临床招募新闻列表")
    @RequiresPermissions("ydz:clinicalnews:edit")
    @Log(title = "临床招募新闻列表", businessType = BusinessType.UPDATE)
    @PostMapping("/editState")
    @ResponseBody
    public AjaxResult editState(@RequestBody ClinicalNews clinicalNews)
    {
        return toAjax(clinicalNewsService.updateClinicalNews(clinicalNews));
    }

    /**
     * 导出临床招募新闻列表
     */
    @RequiresPermissions("ydz:clinicalnews:export")
    @Log(title = "临床招募新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出临床招募新闻列表")
    public AjaxResult export(ClinicalNews clinicalNews)
    {
        List<ClinicalNews> list = clinicalNewsService.selectClinicalNewsList(clinicalNews);
        ExcelUtil<ClinicalNews> util = new ExcelUtil<ClinicalNews>(ClinicalNews.class);
        return util.exportExcel(list, "临床招募新闻数据");
    }

    /**
     * 新增临床招募新闻
     */
    @GetMapping("/add")
    @ApiOperation("新增临床招募新闻")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存临床招募新闻
     */
    @ApiOperation("新增保存临床招募新闻")
    @RequiresPermissions("ydz:clinicalnews:add")
    @Log(title = "临床招募新闻", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClinicalNews clinicalNews)
    {
        return toAjax(clinicalNewsService.insertClinicalNews(clinicalNews));
    }

    /**
     * 修改临床招募新闻
     */
    @ApiOperation("修改临床招募新闻")
    @RequiresPermissions("ydz:clinicalnews:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClinicalNews clinicalNews = clinicalNewsService.selectClinicalNewsById(id);
        mmap.put("clinicalNews", clinicalNews);
        return prefix + "/edit";
    }

    @ApiModelProperty("根据id查询临床招募新闻")
    @GetMapping("/get/{id}")
    @ResponseBody
    public ClinicalNews getClinicalById(@PathVariable("id") Long id){
        return clinicalNewsService.selectClinicalNewsById(id);
    }

    /**
     * 修改保存临床招募新闻
     */
    @ApiOperation("修改保存临床招募新闻")
    @RequiresPermissions("ydz:clinicalnews:edit")
    @Log(title = "临床招募新闻", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClinicalNews clinicalNews)
    {
        return toAjax(clinicalNewsService.updateClinicalNews(clinicalNews));
    }

    /**
     * 删除临床招募新闻
     */
    @ApiOperation("删除临床招募新闻")
    @RequiresPermissions("ydz:clinicalnews:remove")
    @Log(title = "临床招募新闻", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clinicalNewsService.deleteClinicalNewsByIds(ids));
    }

    /*
     * 根据临床招募新闻id查询上一篇下一篇
     * */
    @GetMapping("/getUpandDown/{id}")
    @ResponseBody
    public AjaxResult getUpandDown(@PathVariable("id") Long id){
        return clinicalNewsService.getUpandDown(id);
    }

    /*
     * 增加浏览啦
     * */
    @GetMapping("/updateclinicalNewsBrowseNum/{id}")
    @ResponseBody
    public void updateNewsBrowseNum(@PathVariable("id") Long id){
        clinicalNewsService.updateclinicalNewsBrowseNum(id);
    }
}
